package mka.puzzle.form;

import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import mka.puzzle.cartesian.Axis;
import mka.puzzle.draw.PaintShape;
import mka.puzzle.draw.Painter;
import mka.puzzle.draw.Painter2;
import mka.puzzle.shape.Circle;
import mka.puzzle.shape.Line;
import mka.puzzle.shape.Point;
import mka.puzzle.shape.Rectangle;
import mka.puzzle.shape.Shape;
import mka.puzzle.shape.ShapeList;
import mka.puzzle.shape.Square;
import mka.puzzle.util.Function;

public class Form extends JFrame {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});
	}

	private static void createAndShowGUI() {
		// System.out.println("Created GUI on EDT? "
		// + SwingUtilities.isEventDispatchThread());
		SwingUtilities.isEventDispatchThread();

		ShapeList shapeList = new ShapeList();

		PaintShape paintShape = new PaintShape();

		int number = 100;

		// Random Add Element
		for (int i = 0; i < number; i++) {
			Function.addRandomShape(shapeList);
		}

		// Before the graphics are drawn on frame
		long timeBefore = System.currentTimeMillis();
		for (Shape shape : shapeList.getShapeList()) {
			paintShape.addShape(shape);
		}

		Axis ax = new Axis(500);
		paintShape.addShape(ax);

		Point p = new Point(800, 100);
		Square s = new Square(p, 200);
		paintShape.addShape(s);

		JFrame f = new JFrame("Graphic Puzzle");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setPreferredSize(new Dimension(1000, 700));
		f.setLocation(50, 50);
		f.setResizable(false);
		f.add(paintShape);
		f.pack();
		f.setVisible(true);

		// After the graphics were drawn on frame
		long timeAfter = System.currentTimeMillis();
		System.out.println("Time process: " + (timeAfter - timeBefore) + "s");
	}
}
